﻿@{
    Layout = null;
}

<div>
    <div class="col-3 pr-0" style="display: none">
        <label id="INV-Return-OutInventoryId">@ViewData["OutInventoryId"]</label>
        <label id="INV-Return-Parent-ModalID">@ViewData["ModalID"]</label>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">退还库存数量*</span>
        </div>
        <div class="col-9 pl-0 input-group position-relative">
            <input id="INV-Return-EntryQuantity" class="form-control font-rfs border-radius-noleft" placeholder="必需是有效数字" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">退后可领数量*</span>
        </div>
        <div class="col-9 pl-0 input-group position-relative">
            <input id="INV-Return-AvailableQuantity" class="form-control font-rfs border-radius-noleft" placeholder="必需是有效数字" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">退后剩余数量*</span>
        </div>
        <div class="col-9 pl-0 input-group position-relative">
            <input id="INV-Return-ReceivedQuantity" class="form-control font-rfs border-radius-noleft" placeholder="必需是有效数字" />
        </div>
    </div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">退库原因说明*</span>
        </div>
        <div class="col-9 pl-0">
            <input id="INV-Return-DisposalInstructions" class="form-control font-rfs border-radius-noleft" placeholder="必填" />
        </div>
    </div>
    <div class="text-right">
        <button id="INV-Return-confirm" class="btn btn-primary font-rfs">确定</button>
        <button id="INV-Return-cancel" type="button" class="btn btn-info font-rfs">取消</button>
    </div>
</div>

<script>

    $("#INV-Return-confirm").click(function () {
        if ($.trim($("#INV-Return-EntryQuantity").val()).length == 0) {
            alert("退还库存数量不能为空！");
            $("#INV-Return-EntryQuantity").addClass('error-style');
            return false;
        }
        if ($.trim($("#INV-Return-AvailableQuantity").val()).length == 0) {
            alert("退后可领数量不能为空！");
            $("#INV-Return-AvailableQuantity").addClass('error-style');
            return false;
        }
        if ($.trim($("#INV-Return-ReceivedQuantity").val()).length == 0) {
            alert("退后剩余数量不能为空！");
            $("#INV-Return-ReceivedQuantity").addClass('error-style');
            return false;
        }
        if ($.trim($("#INV-Return-DisposalInstructions").val()).length == 0) {
            alert("退库原因不能为空！");
            $("#INV-Return-DisposalInstructions").addClass('error-style');
            return false;
        }

        var jsonStr = {};
        jsonStr["EntryQuantity"] = $.trim($("#INV-Return-EntryQuantity").val());
        jsonStr["AvailableQuantity"] = $.trim($("#INV-Return-AvailableQuantity").val());
        jsonStr["ReceivedQuantity"] = $.trim($("#INV-Return-ReceivedQuantity").val());
        jsonStr["DisposalInstructions"] = $.trim($("#INV-Return-DisposalInstructions").val());

        $.post("ReturnOutInventory", {
            OutInventoryId: $("#INV-Return-OutInventoryId").html(),
            jsonStr: JSON.stringify(jsonStr)
        }, function (data) {
            if (data.indexOf("成功") >= 0) {
                $("#INV-Return-cancel").click();
            } else {
                alert(data);
            }
        });
    });

    $("#INV-Return-cancel").click(function () {
        var modalID = $("#INV-Return-Parent-ModalID").html();
        $("#" + modalID).modal('hide');
    });

</script>
